package com.example.apidocserver.interfaces.facade;

import com.example.apidocserver.application.event.SysUserEvent;
import com.example.apidocserver.infrastructure.enums.HisIdEnum;
import com.example.apidocserver.infrastructure.util.result.ResultData;
import com.example.apidocserver.infrastructure.util.result.ResultUtils;
import com.example.apidocserver.interfaces.assembler.CommonAssembler;
import com.example.apidocserver.interfaces.vo.UserVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 用户业务
 *
 * @author xyqlg
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Resource
    private SysUserEvent sysUserEvent;

    @GetMapping("currentUser")
    public ResultData getCurrentUser() {
        return ResultUtils.success(sysUserEvent.getCurrentUser());
    }

    @PutMapping("history/{type}/{id}")
    public ResultData setUserHis(@PathVariable("type") String type, @PathVariable("id") Integer id) {
        CommonAssembler.checkInt(id);
        CommonAssembler.checkStr(type);
        HisIdEnum hisIdEnum = HisIdEnum.getEnumByCode(type);
        if (Objects.isNull(hisIdEnum)) {
            return ResultUtils.failure("类型不正确。");
        }
        sysUserEvent.setUserHis(hisIdEnum, id);
        return ResultUtils.success();
    }
}
